package com.atguigu.hive.json;

import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;

/**
 * @author Hefei
 * @description
 * @project_name com.atguigu.ad.json.parsejson
 * @since 2023/3/21 1:08
 */
public class ParseJson {

    public static void main(String[] args) {

        JSONArray jsonArray = JSONUtil
                .readJSONArray(new File("D:\\CodingSpace\\etl-test\\parse-json\\src\\main\\resources\\crawler-user-agent.json"), StandardCharsets.UTF_8);


        // Iterator<Object> iterator = jsonArray.stream().iterator();

        Iterator<Object> iterator1 = jsonArray.iterator();

        // int a = 0;
        while (iterator1.hasNext()) {
            // a++;
            JSONObject jsonObject = (JSONObject) iterator1.next();
            String jsonString = jsonObject.toString();
            // String pattern = (String)jsonObject.getByPath("pattern");
            // System.out.println(jsonObject.toString());
            FileUtil.appendString(jsonString+"\n","D:\\CodingSpace\\etl-test\\parse-json\\src\\main\\resources\\result2.txt",StandardCharsets.UTF_8);
        }

    }
}